package com.mmal.example.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.mmal.annotation.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.Map;

/**
 * Created by sigurHe
 * Date2019/10/7.
 * Time:16:32.
 */
@Slf4j
@NotThreadSafe
public class ImmutableExample3 {

    private final static ImmutableList list = ImmutableList.of(1,2,3);

    private final static ImmutableSet set = ImmutableSet.copyOf(list);

    private final static ImmutableMap<Integer, Integer> map = ImmutableMap.of(1, 2,3,4);
    private final static ImmutableMap<Integer, Integer> map2 = ImmutableMap
            .<Integer, Integer>builder().put(1,2).put(3,4).build();

    public static void main(String[] args) {
        // 会抛异常
        list.add(1);
        set.add(1);
        map.put(1, 5);
        map.putIfAbsent(2, 3);
    }
}
